<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Home = {
      template:`
        <div>
          <h2>home组件</h2>
          <button @click="addArr">增加li</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>  
          </ul>
        </div>
      `,
      data(){
        return {
          arr: [1,2,3,4]
        }
      },
      methods: {
        addArr(){
          this.arr.push(this.arr.length+1);
          // 获取到最新的dom
          /* 
          数据修改后，视图更新 是异步的
          无法在数据修改后立即获取更新后最新的dom
          */
         this.$nextTick(()=>{
           console.log(11111);
           console.log(this.$refs.oul.children);
         })
          // console.log(this.$refs.oul.children);
        }
      },
      beforeCreate(){
        console.log('beforeCreate');
      },
      created(){
        // 调用页面 初始化 需要 用到model函数（请求数据接口函数）
        console.log('实例创建完成-created');
      },
      beforeMount(){
        console.log('dom渲染完成之前');
      
      },
      mounted(){
        console.log('dom渲染完成');
        
      },
      beforeUpdate(){
        console.log('更新完成之前');
        // console.log(this.$refs.oul.children);
        // this.$refs.oul.lastChild.style.background="purple";
      },
      updated(){
        console.log('视图更新完成');
        
      },
      beforeDestroy(){
        console.log('卸载之前');
      },
      destroyed(){
        console.log('组件已经卸载');
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>